package org.compactmvc.demo.model
{
	import org.compactmvc.services.xmlservice.XMLService;
	import org.compactmvc.patterns.Controller;
	
	import flash.net.URLRequest;
	
	import org.compactmvc.demo.ApplicationController;
	
	public final class ApplicationModel extends XMLService
	{
		public static const NAME:String = 'ApplicationModel';
		
		public var buttonLabel:String = 'TestLabel';

		public var settingsData:XML;
		public var settings2Data:XML;
		
		public function ApplicationModel(name:String, controller:Controller)
		{
			super(name, controller);
		}
		
		override public function registerHandler():void
		{
			loadConfig();
		}

		
		public function loadConfig():void
		{
			load(new URLRequest(ApplicationController.PATH_SETTINGS),  settingsResultHandler, faultHandler);
			load(new URLRequest(ApplicationController.PATH_SETTINGS2),  settings2ResultHandler, faultHandler);
		}
		
		protected function settingsResultHandler():void
		{
			settingsData = data;
		}
		
		protected function settings2ResultHandler():void
		{
			settings2Data = data;
			sendNotification(ApplicationController.SETTINGS_LOADED);
		}
		
		protected function faultHandler(msg:String):void
		{
			trace("Fault Handler");
		}
	}
}